<template>
  <Container class="dealer-pointcheck-list">
    <HeadFormItem
      slot="header"
      :list="list"
      @onSearchBtnClick="onSearchBtnClick"
      @onAddBtnClick="onAddBtnClick"/>
    <Tabs v-model="tab">
      <export-btn @onExport="onExport" class="item" slot="extra"></export-btn>
      <TabPane label="经销商积分审核" name="tab1">
         <homeTable
          :list="list"
          @getData="getData"
          @onPageSizeChange="onPageSizeChange"
          @onPageChange="onPageChange"
          @onSelectionChange="onSelectionChange"
        />
      </TabPane>
    </Tabs>
    <DealerPointDetailModelItem @complete='getData' ref="ModelItem" />
  </Container>
</template>
<script>
import FundCheckListData from './list/DealerPointCheckListData'
import HeadFormItem from './list/HeadFormItem'
import DealerPointDetailModelItem from './list/DealerPointDetailModelItem'
import homeTable from '@/components/homeTable'

import { clearEmpty, formatDate } from '@/util'
export default {
  name: 'welfare/dealerpointcheck/list',
  components: {
    HeadFormItem,
    DealerPointDetailModelItem,
    homeTable
  },
  data() {
    return {
      tab: "tab1",
      list: FundCheckListData,
      productIds: []
    };
  },
  mounted() {
    this.getData();
    this.$bus.$on('checklRow', this.checklRow)
    this.$bus.$on('infoRow', this.infoRow)
  },
  destroyed() {
    this.$bus.$off();
  },
  methods: {
    onSearchBtnClick() {
      this.list.currentPage = 1;
      this.getData();
    },
    infoRow(row) {
      this.$router.push({
        name: 'welfare/dealerpointcheck/info',
        query: {
          id: row.id
        }
      })
    },
    checklRow(row) {
      this.$refs.ModelItem.openModal(row)
    },
    getData() {
      this.productIds = [];
      this.list.status = "loading";
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        auditStatus: this.list.form.auditStatus
      };
      if (this.list.form.month) {
        let str = formatDate(this.list.form.month).slice(0, 7)
        param.year = str.split('-')[0]
        param.month = str.split('-')[1]
      }
      if (this.list.form.province) {
        param.areaName = this.list.form.provinceName
      }
      param = clearEmpty(param)
      this.$jsonPost("/distributor/integral/month_audit/page", param).then(data => {
          this.list.data = [];
          this.list.totalItem = Number(data.total);
          this.list.totalItem = Number(data.total);
          this.list.data = (data.records || []).map(item => {
            item.areaName = `${item.provinceName || ''}${item.cityName || ''}${item.areaName || ''}`
            return item
          });
          this.list.status = "pass";
        })
        .catch(() => {
          this.list.status = "error";
        });
    },
    onExport() {
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        auditStatus: this.list.form.auditStatus
      };
      if (this.list.form.month) {
        let str = formatDate(this.list.form.month).slice(0, 7)
        param.year = str.split('-')[0]
        param.month = str.split('-')[1]
      }
      if (this.list.form.province) {
        param.areaName = this.list.form.provinceName
      }
      param = clearEmpty(param)
      this.$ajaxPost('/distributor/integral/month_audit/export', param).then(() => {})
        this.$Modal.confirm({
          title: '提示',
          content: '跳转到导出列表页面？',
          onOk: () => {
            this.$router.push('/home/export/list')
          }
        })
    },
    onSelectionChange(selection) {
      this.productIds = (selection || []).map(item => item.id);
    },
    onPageChange(number) {
      this.list.currentPage = number;
      this.getData();
    },
    onPageSizeChange(pageSize) {
      this.list.currentPage = 1;
      this.list.pageSize = pageSize;
      this.getData();
    }
  },
  watch: {
  }
};
</script>
